home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / snip9503 / scrnsave.c < prev    next >
C/C++ Source or Header  |  1995-03-14  |  2KB  |  82 lines

  1. /*
  2. **  Portable PC screen functions
  3. **  Public domain by Bob Stout
  4. **  Uses VIDPORT.C, also from SNIPPETS
  5. **  Uses _fmemcpy(), available in most PC compiler libraries
  6. **  A portable _fmemcpy() is available in FMEMOPS.C, also from SNIPPETS
  7. */
  8.  
  9. #include <stdlib.h>
  10. #include "scrnmacs.h"         /* Also in SNIPPETS     */
  11.  
  12. /*
  13. **  Save the text screen
  14. */
  15.  
  16. struct SCREEN *SaveScrn(void)
  17. {
  18.       struct SCREEN *screen;
  19.  
  20.       if (NULL == (screen = malloc(sizeof(struct SCREEN))))
  21.             return NULL;
  22.       if (NULL == (screen->vbuf = malloc(SCRNBYTES)))
  23.       {
  24.             free(screen);
  25.             return NULL;
  26.       }
  27.       _fmemcpy((unsigned short FAR *)(screen->vbuf), SCRBUFF, SCRNBYTES);
  28.       GetCurPos(&screen->curX, &screen->curY);
  29.       return screen;
  30. }
  31.  
  32. /*
  33. **  Restore the text screen
  34. */
  35.  
  36. void RestoreScrn(struct SCREEN *screen)
  37. {
  38.       _fmemcpy(SCRBUFF, (unsigned short FAR *)(screen->vbuf), SCRNBYTES);
  39.       GotoXY(screen->curX, screen->curY);
  40. }
  41.  
  42. /*
  43. **  Free a saved screen buffer
  44. */
  45.  
  46. void FreeScrnBuf(struct SCREEN *screen)
  47. {
  48.       free(screen->vbuf);
  49.       free(screen);
  50. }
  51.  
  52.  
  53. #ifdef TEST
  54.  
  55. #include <stdio.h>
  56. #include <conio.h>
  57.  
  58. /*
  59. **  Run this test with a screenful of misc. stuff
  60. */
  61.  
  62. main()
  63. {
  64.       struct SCREEN *screen;
  65.       int vatr = GetCurAtr();
  66.  
  67.       if (NULL == (screen = SaveScrn()))
  68.       {
  69.             puts("Unable to save the screen");
  70.             return 1;
  71.       }
  72.       ClrScrn(vatr);
  73.       GotoXY(0, 0);
  74.       fputs("ClrScrn() tested", stderr);
  75.       fputs("\nHit any key to continue...\n", stderr);
  76.       getch();
  77.       RestoreScrn(screen);
  78.       FreeScrnBuf(screen);
  79. }
  80.  
  81. #endif
  82.